﻿<template>
  <a-drawer
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @close="
      () => {
        this.visible = false
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="供货单位编号" prop="Code">
          <a-input v-model="entity.Code" autocomplete="off">
            <a-icon slot="prefix" type="scan" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="供货单位名称" prop="Name">
          <a-input v-model="entity.Name" autocomplete="off">
            <a-icon slot="prefix" type="user" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="供货单位简称" prop="Abbreviation">
          <a-input v-model="entity.Abbreviation" autocomplete="off">
            <a-icon slot="prefix" type="user" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="供货单位类型" prop="Type">
          <!-- <enum-select code="SupplierType" v-model="entity.Type"></enum-select> -->
           <a-select v-model="entity.Type" >
            <a-select-option v-for="(item, index) in RackList" :value="item.Id" :key="index"
              >{{ item.SupplierTypeName }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="电话" prop="Phone">
          <a-input v-model="entity.Phone" autocomplete="off">
            <a-icon slot="prefix" type="phone" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="传真" prop="Fax">
          <a-input v-model="entity.Fax" autocomplete="off">
            <a-icon slot="prefix" type="printer" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="Email" prop="Email">
          <a-input v-model="entity.Email" autocomplete="off">
            <a-icon slot="prefix" type="mail" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="联系人" prop="ContactName">
          <a-input v-model="entity.ContactName" autocomplete="off">
            <a-icon slot="prefix" type="idcard" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="地址" prop="Address">
          <a-input v-model="entity.Address" autocomplete="off">
            <a-icon slot="prefix" type="compass" />
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="供货单位状态" prop="States">
          <a-radio-group v-model="entity.States" :default-value="false" button-style="solid">
            <a-radio-button :value="false"> 停用 </a-radio-button>
            <a-radio-button :value="true"> 启用 </a-radio-button>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="备注" prop="Remarks">
          <a-textarea v-model="entity.Remarks" autocomplete="off"></a-textarea>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '10px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1
      }"
    >
      <a-button
        :style="{ marginRight: '8px' }"
        @click="
          () => {
            this.visible = false
          }
        "
        >取消</a-button
      >
      <a-button type="primary" @click="handleSubmit">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import EnumSelect from '../../../components/BaseEnum/BaseEnumSelect'
export default {
  components: {
    // EnumSelect
  },
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      RackList: [], //类型list
      rules: {
        Name: [{ required: true, message: '请输入供货单位名称', trigger: 'blur' }],
        Type: [{ required: true, message: '请选择供货单位类型', trigger: 'change' }],
        // Code: [{ required: true, message: '请输入供货单位编号', trigger: 'blur' }]
      },
      title: ''
    }
  },
  methods: {
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      console.log(1)
      this.$http.post('/PB/pb_suppliertype/GetDataList', { }).then(resJson => {
        this.loading = false
        this.RackList = resJson.Data
      })
      if (id) {
        this.loading = true
        this.$http.post('/PB/PB_Supplier/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/PB/PB_Supplier/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
